package com.epfresh.bean;

import com.epfresh.global.CartHelper;
import com.epfresh.utils.FormatUtil;
import com.epfresh.utils.TimeStringUtils;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by zhaozhenqiang on 2018/6/19.
 */

public class OfferMyList  implements CartHelper.CartHelperTools {

    /**
     * productOfferId : 18
     * code : 201806191754450012
     * cityId : 6401
     * accountId : 2487
     * productOfferDetailsId : 18
     * productId : 4130
     * storeId : 24
     * chargeUnit : 斤
     * quantity : 20.0
     * remark : null
     * price : null
     * status : 1
     * reason : null
     * createTime : 2018-06-19 17:54:46
     * offerTime : null
     * overTime : null
     * offerDuration : null
     * title : 山核桃味焦糖瓜子
     * productStatus : 1
     * package_size : 10.0
     * oldPrice : 8.0
     * package_unit : 斤
     * package_container : 箱
     * name : 天天鲜四季鲜
     * offerStatus : 报价中
     * offerStatusCopy : 忙碌，过会问
     * imageUrl : http://imgtest.epfresh.com/2017%2F4%2F23%2F1493017549989_c4aeb93dgw1f9olvvcgqzj20ey0bydh0.jpg-PRODUCTTHUMBNAIL
     * originalPrice : ¥8.00/斤
     * packingSpecification : 10.00斤/箱
     * isAcceptOrders
     * <p>
     * offerBuyRemindTime;
     * offerSellRemindTime;
     */
    private String offerBuyRemindTime;
    private String offerSellRemindTime;
    private static double askWaitTime = 10;

    public static double getAskWaitTime() {
        return askWaitTime;
    }

    public static void setAskWaitTime(double askWaitTime) {
        OfferMyList.askWaitTime = askWaitTime;
    }

    private boolean lastBuyFiveFlag;

    public boolean isLastBuyFiveFlag() {
        return lastBuyFiveFlag;
    }

    public void setLastBuyFiveFlag(boolean lastBuyFiveFlag) {
        this.lastBuyFiveFlag = lastBuyFiveFlag;
    }

    public long getNowTime() {
        return System.currentTimeMillis();
    }

    public String getOfferSellRemindTime() {

        if (offerTime != null) {
            long tEnd = TimeStringUtils.formatTimeLong(offerTime);
            tEnd += getOfferDuration()*60*1000;
            //tEnd += 60 * askWaitTime;
            if((tEnd - getNowTime()) / 1000<300){
                setLastBuyFiveFlag(true);
            }
            return getRightTime(tEnd);
        }
        return "";
    }

    public String getOfferBuyRemindTime() {
        if(createTime == null) {
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
            createTime = (df.format(new Date()));
        }
        if (createTime != null) {
            long tEnd = TimeStringUtils.formatTimeLong(createTime);
            tEnd += 60*1000 * askWaitTime;
            return getRightTime(tEnd);
        }
        return "";
    }

    private String getRightTime(long tEnd) {
        long tLocale = getNowTime();
        long nowRemindTime;
        if (tLocale <= tEnd) {//活动进行中
            nowRemindTime = (tEnd - tLocale) / 1000;
            String timeFlag;
            if (nowRemindTime > 60) {
                long hour = nowRemindTime / 3600;
                long minus = nowRemindTime % 3600 / 60;
                long sec = nowRemindTime % 60;
                if (hour < 10) {
                    timeFlag = "";//"0" + hour;


                    if (minus < 10) {
                        timeFlag += "0" + minus;
                    } else {
                        timeFlag += "" + minus;
                    }
                    if (sec < 10) {
                        timeFlag += ":0" + sec;
                    } else {
                        timeFlag += ":" + sec;
                    }

                } else {
                    timeFlag = "" + hour;

                    if (minus < 10) {
                        timeFlag += ":0" + minus;
                    } else {
                        timeFlag += ":" + minus;
                    }
                    if (sec < 10) {
                        timeFlag += ":0" + sec;
                    } else {
                        timeFlag += ":" + sec;
                    }

                }
                return timeFlag;


            } else if (nowRemindTime > 0) {
                if (nowRemindTime < 10) {
                    timeFlag = "00:0" + nowRemindTime;
                } else {
                    timeFlag = "00:" + nowRemindTime;
                }
                return timeFlag;
            }else
                return "00:00";
        } else
            return "00:00";
    }

    private boolean isAcceptOrders;

    public boolean isAcceptOrders() {
        return isAcceptOrders;
    }

    public void setAcceptOrders(boolean acceptOrders) {
        isAcceptOrders = acceptOrders;
    }

    private String promotionItemId;
    private Double moq;
    private Double incr;
    private Double inventory;

    public Double getMoq() {
        return moq;
    }

    public void setMoq(Double moq) {
        this.moq = moq;
    }

    public Double getIncr() {
        return incr;
    }

    public void setIncr(Double incr) {
        this.incr = incr;
    }

    public Double getInventory() {
        return inventory;
    }

    public void setInventory(Double inventory) {
        this.inventory = inventory;
    }

    @Override
    public String getUniqueKey() {
        return getIdPlus();
    }
    private String shoppingCarId;

    public String getShoppingCarId() {
        return shoppingCarId;
    }

    public void setShoppingCarId(String shoppingCarId) {
        this.shoppingCarId = shoppingCarId;
    }

    public String getIdPlus() {
        if (promotionItemId != null ){
            return productId+"|"+promotionItemId;
        }
        return productId;
    }
    public double getCount() {
        if(shoppingCarProductCount==null)
            return 0;
        else
            return shoppingCarProductCount;
    }

    public void setCount(double count) {
        this.shoppingCarProductCount = count;
        this.count = count;
    }
    private double count;

    public String getPromotionItemId() {
        return promotionItemId;
    }

    public void setPromotionItemId(String promotionItemId) {
        this.promotionItemId = promotionItemId;
    }

    Double shoppingCarProductCount;

    public Double getShoppingCarProductCount() {
        if (shoppingCarProductCount==null)
            return 0.00;
        return shoppingCarProductCount;
    }

    public void setShoppingCarProductCount(Double shoppingCarProductCount) {
        this.shoppingCarProductCount = shoppingCarProductCount;
    }

    public String getGoodsCount() {
        String s = FormatUtil.subZeroAndDot(getCount() + "");
        if ("0".equals(s)) {
            return "";
        }
        return s;
    }

    private String productOfferId;
    private String code;
    private String cityId;
    private String accountId;
    private String productOfferDetailsId;
    private String productId;
    private String lastSnapshotId;
    private String storeId;
    private String chargeUnit;
    private String quantity;
    private String remark;
    private String price;
    private int status;
    private String reason;
    private String createTime;
    private String offerTime;
    private String overTime;
    private Double offerDuration;
    private String title;
    private int productStatus;
    private double package_size;
    private double oldPrice;
    private String package_unit;
    private String package_container;
    private String name;
    private String offerStatus;
    private String offerStatusCopy;
    private String imageUrl;
    private String originalPrice;
    private String packingSpecification;
    private String nowPrice;

    public String getLastSnapshotId() {
        return lastSnapshotId;
    }

    public void setLastSnapshotId(String lastSnapshotId) {
        this.lastSnapshotId = lastSnapshotId;
    }


    public String getNowPrice() {
        return nowPrice;
    }

    public void setNowPrice(String nowPrice) {
        this.nowPrice = nowPrice;
    }

    public String getProductOfferId() {
        return productOfferId;
    }

    public void setProductOfferId(String productOfferId) {
        this.productOfferId = productOfferId;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getCityId() {
        return cityId;
    }

    public void setCityId(String cityId) {
        this.cityId = cityId;
    }

    public String getAccountId() {
        return accountId;
    }

    public void setAccountId(String accountId) {
        this.accountId = accountId;
    }

    public String getProductOfferDetailsId() {
        return productOfferDetailsId;
    }

    public void setProductOfferDetailsId(String productOfferDetailsId) {
        this.productOfferDetailsId = productOfferDetailsId;
    }

    public String getProductId() {
        return productId;
    }

    public void setProductId(String productId) {
        this.productId = productId;
    }

    public String getStoreId() {
        return storeId;
    }

    public void setStoreId(String storeId) {
        this.storeId = storeId;
    }

    public String getChargeUnit() {
        return chargeUnit;
    }

    public void setChargeUnit(String chargeUnit) {
        this.chargeUnit = chargeUnit;
    }

    public String getQuantity() {
        return quantity;
    }

    public void setQuantity(String quantity) {
        this.quantity = quantity;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public String getPrice() {
        return price;
    }

    public void setPrice(String price) {
        this.price = price;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getReason() {
        return reason;
    }

    public void setReason(String reason) {
        this.reason = reason;
    }

    public String getCreateTime() {
        return createTime;
    }

    public void setCreateTime(String createTime) {
        this.createTime = createTime;
    }

    public String getOfferTime() {
        return offerTime;
    }

    public void setOfferTime(String offerTime) {
        this.offerTime = offerTime;
    }

    public String getOverTime() {
        return overTime;
    }

    public void setOverTime(String overTime) {
        this.overTime = overTime;
    }

    public Double getOfferDuration() {
        if(offerDuration == null)
            return 0.00;
        return offerDuration;
    }

    public void setOfferDuration(Double offerDuration) {
        this.offerDuration = offerDuration;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public int getProductStatus() {
        return productStatus;
    }

    public void setProductStatus(int productStatus) {
        this.productStatus = productStatus;
    }

    public double getPackage_size() {
        return package_size;
    }

    public void setPackage_size(double package_size) {
        this.package_size = package_size;
    }

    public double getOldPrice() {
        return oldPrice;
    }

    public void setOldPrice(double oldPrice) {
        this.oldPrice = oldPrice;
    }

    public String getPackage_unit() {
        return package_unit;
    }

    public void setPackage_unit(String package_unit) {
        this.package_unit = package_unit;
    }

    public String getPackage_container() {
        return package_container;
    }

    public void setPackage_container(String package_container) {
        this.package_container = package_container;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getOfferStatus() {
        return offerStatus;
    }

    public void setOfferStatus(String offerStatus) {
        this.offerStatus = offerStatus;
    }

    public String getOfferStatusCopy() {
        return offerStatusCopy;
    }

    public void setOfferStatusCopy(String offerStatusCopy) {
        this.offerStatusCopy = offerStatusCopy;
    }

    public String getImageUrl() {
        return imageUrl;
    }

    public void setImageUrl(String imageUrl) {
        this.imageUrl = imageUrl;
    }

    public String getOriginalPrice() {
        return originalPrice;
    }

    public void setOriginalPrice(String originalPrice) {
        this.originalPrice = originalPrice;
    }

    public String getPackingSpecification() {
        return packingSpecification;
    }

    public void setPackingSpecification(String packingSpecification) {
        this.packingSpecification = packingSpecification;
    }
}
